package com.xthh.esl;

import android.content.Context;

import com.xthh._function.HH_Logging;
import com.xthh._function.HH_SystemUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ThreadRunNFCCommand  extends Thread{


    private final String TAG = "ThreadDownloadTemplate";

    Context ctx;
    boolean isRun = false;
    private boolean bGetPic = false;
    NFCTask currentTask;

    public ThreadRunNFCCommand(Context context) {
        ctx = context;
    }

    @Override
    public synchronized void start() {
        super.start();
    }

    @Override
    public void run() {
        super.run();

        while (isRun) {
            HH_SystemUtil.Sleep(100);

            if (bGetPic && currentTask != null) {

                HH_Logging.i(TAG, "新任务");


                IsoDepUtils.startIsoDep(currentTask);

                currentTask = null;
                bGetPic = false;
            }
        }
    }

    public void setRunning(boolean b) {
        isRun = b;
    }

    public void close() {
        isRun = false;
    }

    public void addTask(NFCTask task){
        if (!bGetPic){
            currentTask= new NFCTask(task.getTag(), task.getCommandNFC(), task.getTpParams(), task.getMsg(), task.getPath(), task.getBindInfo());
            bGetPic = true;
        }
    }
}
